const key = 'token';
//本文件用于设置token登录信息

//localstorage只要不手动清除，永远存在
export function logOut() {
    removeUser();
    removeToken();
    removeCollapse();
}

export function getToken() {
    return window.localStorage.getItem(key);
}

export function setToken(token) {
    return window.localStorage.setItem(key, token);
}

export function removeToken() {
    return window.localStorage.removeItem(key);
}

export function getUser() {
    return JSON.parse(window.localStorage.getItem("user"));
}

export function setUser(user) {
    window.localStorage.setItem("user", JSON.stringify(user));
}

export function removeUser() {
    return window.localStorage.removeItem("user");
}

export function setCollapse(flag) {
    window.localStorage.setItem('col', flag);
}

export function getCollapse() {
    //日了够了，Boolean(str)强制转化是没用的，都是true
    if (window.localStorage.getItem('col')) {
        return /^true$/i.test(window.localStorage.getItem('col'));
    } else {
        setCollapse(false);
        return false;
    }
}

export function removeCollapse() {
    window.localStorage.removeItem('col');
}




